package com.cy.zs.hp.controller;


import com.cy.zs.hp.common.exception.HpException;
import com.cy.zs.hp.common.jsonResult.JsonResult;
import com.cy.zs.hp.model.HisUser;
import com.cy.zs.hp.service.IHisUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 该表保存注册用户信息 前端控制器
 * </p>
 *
 * @author cgb2008
 * @since 2020-11-28
 */
@RestController
@RequestMapping("/user/")
public class HisUserController {
    @Autowired
    IHisUserService service;
    @RequestMapping("doregister")
    public JsonResult doInsert(@RequestBody @Valid HisUser hisUser, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            String errors=bindingResult.getFieldError().getDefaultMessage();
            throw new HpException(errors);
        }
        service.insert(hisUser);
        return new JsonResult("注册成功");
    }
    @RequestMapping("dologin")
    public  JsonResult doLogin(@RequestBody @Valid HisUser hisUser,BindingResult BindingResult){
        if (BindingResult.hasErrors()) {
            String errors = BindingResult.getFieldError().getDefaultMessage();
            throw  new HpException(errors);
        }
        service.login(hisUser);
        return  new JsonResult("登录成功");

    }





}
